import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

public class Dome {
    //遍历
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        System.out.println(list);

        System.out.println("===========1=============");

        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

        System.out.println("============2============");

        for(int x : list) {
            System.out.print(x + " ");
        }
        System.out.println();

        System.out.println("============3============");

        //迭代器
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");     //i++
        }
        System.out.println();

        System.out.println("===========4==============");

        ListIterator<Integer> lit = list.listIterator();
        while(lit.hasNext()) {
            System.out.print(lit.next() + " ");     //i++
        }
        System.out.println();

        System.out.println("===========5==============");
        //倒着打印
        ListIterator<Integer> lit1 = list.listIterator(list.size());
        while(lit1.hasPrevious()) {
            System.out.print(lit1.previous() + " ");
        }
        System.out.println();
    }
}
